﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SisLegal.Model;
using System.Web.Services;

namespace SisLegal.Expedient
{
    public class ArticleDetail
    {
        public string NameGenerico;
        public string NameSubGenerico;
        public string Name; 
    }

    public partial class FiscalFolderNewForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                DDL_Participation_Seal.DataSource = Enumeration.GetAll<eParticipation_Seal_Fiscal_Folder>();
                DDL_Participation_Seal.DataTextField = "Value";
                DDL_Participation_Seal.DataValueField = "Key";
                DDL_Participation_Seal.DataBind();

                DDL_Money.DataSource = Enumeration.GetAll<eMoney>();
                DDL_Money.DataTextField = "Value";
                DDL_Money.DataValueField = "Key";
                DDL_Money.DataBind();

                DDL_Type_Process.DataSource = Enumeration.GetAll<eType_Process_Fiscal_Folder>();
                DDL_Type_Process.DataTextField = "Value";
                DDL_Type_Process.DataValueField = "Key";
                DDL_Type_Process.DataBind();

                DDL_Contingency_Rate.DataSource = Enumeration.GetAll<eContingency_Rate>();
                DDL_Contingency_Rate.DataTextField = "Value";
                DDL_Contingency_Rate.DataValueField = "Key";
                DDL_Contingency_Rate.DataBind();

                DDL_Assigned_Person.DataSource = Enumeration.GetAll<eAssigned_Person>();
                DDL_Assigned_Person.DataTextField = "Value";
                DDL_Assigned_Person.DataValueField = "Key";
                DDL_Assigned_Person.DataBind();

                DDL_Physical_Location_Files.DataSource = Enumeration.GetAll<ePhysical_Location_Files>();
                DDL_Physical_Location_Files.DataTextField = "Value";
                DDL_Physical_Location_Files.DataValueField = "Key";
                DDL_Physical_Location_Files.DataBind();


                LawyerManager lawyer = new LawyerManager();
                DDL_Lawyer.DataSource = lawyer.GetAll();
                DDL_Lawyer.DataTextField = "Name";
                DDL_Lawyer.DataValueField = "ID";
                DDL_Lawyer.DataBind();
            }

        }

        protected void btnSearchCrime_Click(object sender, EventArgs e)
        {
            CrimeSpecificManager crimeManager = new CrimeSpecificManager();
            CrimeSpecific crime = crimeManager.GetByArticle(Convert.ToInt32(txtArticle.Text));
            txtArticleDetail1.Text = crime.NameGenerico;
            txtArticleDetail2.Text = crime.NameSubGenerico;
            txtArticleDetail3.Text = crime.Name;
        }

        [WebMethod]
        public static ArticleDetail GetArticleDetail(int txtArticle)
        {
            CrimeSpecificManager crimeManager = new CrimeSpecificManager();
            CrimeSpecific crime = crimeManager.GetByArticle(txtArticle);
            ArticleDetail detail = new ArticleDetail();
            detail.NameGenerico=crime.NameGenerico;
            detail.NameSubGenerico=crime.NameSubGenerico;
            detail.Name=crime.Name;

            var values = new
            {
                ProductId = 12,
                ProcessId = 23,
                Note = "This is Note"
            };

            return detail;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Model.FiscalFolderManager typeProcessManager = new Model.FiscalFolderManager();
            Model.FiscalFolder fiscalFolder = new Model.FiscalFolder();

            if (txtYear.Text == "") { txtYear.Text = "0"; }
            if (txtFechaHechos.Text == "") { txtFechaHechos.Text = "0001-01-01"; }
            if (txtFechaNoticicacionSeal.Text == "") { txtFechaNoticicacionSeal.Text = "0001-01-01"; }
            if (txtFechaInicio.Text == "") { txtFechaInicio.Text = "0001-01-01"; }
            if (txtMontoPretension.Text == "") { txtMontoPretension.Text = "0"; }
            if (txtArticle.Text == "") { txtArticle.Text = "0"; }

            fiscalFolder.NroFiscalFolder= txtNroFiscalFolder.Text ;
            fiscalFolder.Year = Convert.ToInt32(txtYear.Text);
            fiscalFolder.Fiscalia = txtFiscalia.Text;
            fiscalFolder.FiscalCargo = txtFiscalCargo.Text;
            fiscalFolder.FechaHechos = Convert.ToDateTime(txtFechaHechos.Text);
            fiscalFolder.FechaNoticicacionSeal = Convert.ToDateTime(txtFechaNoticicacionSeal.Text);
            fiscalFolder.FechaInicio = Convert.ToDateTime(txtFechaInicio.Text);
            fiscalFolder.MontoPretension = Convert.ToDecimal(txtMontoPretension.Text);
            fiscalFolder.ParticipationSeal = Convert.ToInt32(DDL_Participation_Seal.SelectedItem.Value);
            fiscalFolder.Article = Convert.ToInt32(txtArticle.Text);
            fiscalFolder.Money = Convert.ToInt32(DDL_Money.SelectedItem.Value);
            fiscalFolder.TypeProcess = Convert.ToInt32(DDL_Type_Process.SelectedItem.Value);
            fiscalFolder.ContingencyRate = Convert.ToInt32(DDL_Contingency_Rate.SelectedItem.Value);
            fiscalFolder.PoliciaCargo = txtPoliciaCargo.Text;
            fiscalFolder.Denunciante = txtDenunciante.Text;
            fiscalFolder.Denunciado = txtDenunciado.Text;
            fiscalFolder.Agraviado = txtAgraviado.Text;
            fiscalFolder.DocumentoInicial = txtDocumentoInicial.Text;
            fiscalFolder.Sumilla = txtSumilla.Text;
            fiscalFolder.Observaciones = txtObservaciones.Text;
        //---------------------------------------------
            fiscalFolder.AssignedPerson = Convert.ToInt32(DDL_Assigned_Person.SelectedItem.Value);
            fiscalFolder.Lawyer = Convert.ToInt32(DDL_Lawyer.SelectedItem.Value);
            fiscalFolder.OrdenServicio = txtOrdenServicio.Text;
            fiscalFolder.NroRecibo = txtNroRecibo.Text;
            fiscalFolder.TerminosReferencia = txtTerminosReferencia.Text;
            fiscalFolder.AbogadoSeal = txtAbogadoSeal.Text;
            fiscalFolder.PracticanteSeal = txtPracticanteSeal.Text;
            fiscalFolder.PhysicalLocationFiles = Convert.ToInt32(DDL_Physical_Location_Files.SelectedItem.Value);




            int newArticleID = typeProcessManager.Save(fiscalFolder);

            if (newArticleID != 0)
            {
                //lblConfirmation.Text = "Grabado Satifactoriamente";
                //lblConfirmation.Visible = true;
            }
            else
            {
                //lblConfirmation.Text = "Error en la Grabacion";
                //lblConfirmation.Visible = true;
            }

            ClearForm();
        }

        private void ClearForm()
        {
            //txtName.Text = String.Empty;
        }
    }
}